package org.al.poc.router;

import java.io.IOException;
import java.net.Socket;

import org.al.poc.persistence.beans.Connection;
import org.al.poc.persistence.beans.Order;
import org.al.poc.sockets.SocketManager;

public class ClientPart {
	
	private SocketManager manager;

	
	
	public ClientPart(WebServerInfo server) throws IOException {
		Socket socket = new Socket(server.getHots(), server.getPort());
		manager = new SocketManager(socket);
	}
	
	
	private Object transmitObject (Object object) throws IOException {
		manager.writeObject(object);
		Object response = manager.readObject();
		return response;
	}

	
	public Connection transmitConnection (Connection connection) throws IOException {
		
		Object response = transmitObject(connection);
		
		if (response instanceof Connection) {
			return (Connection) response;
		}
		
		return null;
	}


	public Order transmitOrder (Order order) throws IOException {
		
		Object response = transmitObject(order);
		
		if (response instanceof Order) {
			return (Order) response;
		}
		
		return null;
	}

}